home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_imageclass.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  4KB  |  184 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <intuition/classes.h>
  17.  
  18. #include <clib/alib_protos.h>    /* For Coerce/Do/DoSuperMethod */
  19.  
  20. /*****************************************************************************/
  21.  
  22. #include "Assert.h"
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27. STATIC ULONG
  28. ImageClassDraw(struct Image *image,struct impDraw *drawMsg,ImageInfo *imageInfo)
  29. {
  30.     LTP_DrawBox(drawMsg->imp_RPort,drawMsg->imp_DrInfo,image->LeftEdge + drawMsg->imp_Offset.X,image->TopEdge + drawMsg->imp_Offset.Y,image->Width,image->Height,drawMsg->imp_State == IDS_SELECTED,drawMsg->imp_State == IDS_DISABLED,imageInfo);
  31.  
  32.     return(TRUE);
  33. }
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39. STATIC ULONG
  40. ImageClassErase(struct Image *image,struct impErase *eraseMsg)
  41. {
  42.     LTP_EraseBox(eraseMsg->imp_RPort,eraseMsg->imp_Offset.X + image->LeftEdge,eraseMsg->imp_Offset.Y + image->TopEdge,image->Width,image->Height);
  43.  
  44.     return(TRUE);
  45. }
  46.  
  47.  
  48. /*****************************************************************************/
  49.  
  50. STATIC ULONG
  51. ImageClassNew(struct IClass *class,Object *object,struct opSet *SetMethod)
  52. {
  53.     struct TagItem *Item;
  54.  
  55.     if(Item = FindTagItem(IIA_ImageType,SetMethod->ops_AttrList))
  56.     {
  57.         struct Image *NewImage;
  58.  
  59.         if(NewImage = (struct Image *)DoSuperMethodA(class,object,(Msg)SetMethod))
  60.         {
  61.             struct ImageInfo    *MoreInfo = INST_DATA(class,NewImage);
  62.             struct TagItem        *List = SetMethod->ops_AttrList;
  63.  
  64.             memset(MoreInfo,0,sizeof(struct ImageInfo));
  65.  
  66.             MoreInfo->ImageType = Item->ti_Data;
  67.  
  68.             while(Item = NextTagItem(&List))
  69.             {
  70.                 switch(Item->ti_Tag)
  71.                 {
  72.                     case IIA_GlyphWidth:
  73.                         MoreInfo->GlyphWidth = Item->ti_Data;
  74.                         break;
  75.  
  76.                     case IIA_GlyphHeight:
  77.                         MoreInfo->GlyphHeight = Item->ti_Data;
  78.                         break;
  79.  
  80.                     case IIA_Lines:
  81.                         MoreInfo->Lines = (STRPTR *)Item->ti_Data;
  82.                         break;
  83.  
  84.                     case IIA_LineCount:
  85.                         MoreInfo->LineCount = Item->ti_Data;
  86.                         break;
  87.  
  88.                     case IIA_KeyStroke:
  89.                         MoreInfo->KeyStroke = (STRPTR)Item->ti_Data;
  90.                         break;
  91.  
  92.                     case IIA_Emboss:
  93.                         MoreInfo->Emboss = Item->ti_Data;
  94.                         break;
  95.  
  96.                     case IIA_Label:
  97.                         MoreInfo->Label = (STRPTR)Item->ti_Data;
  98.                         break;
  99.  
  100.                     case IIA_Font:
  101.                         if(!(MoreInfo->Font = OpenFont((struct TextAttr *)Item->ti_Data)))
  102.                         {
  103.                             CoerceMethod(class,object,OM_DISPOSE);
  104.  
  105.                             return(NULL);
  106.                         }
  107.  
  108.                         break;
  109.                 }
  110.             }
  111.  
  112.             if(V39)
  113.             {
  114.                 if(!(MoreInfo->FrameImage = (struct Image *)NewObject(NULL,FRAMEICLASS,
  115.                     IA_Left,        NewImage->LeftEdge,
  116.                     IA_Top,            NewImage->TopEdge,
  117.                     IA_Width,        NewImage->Width,
  118.                     IA_Height,        NewImage->Height,
  119.                     IA_FrameType,    FRAME_BUTTON,
  120.                 TAG_DONE)))
  121.                 {
  122.                     CoerceMethod(class,object,OM_DISPOSE);
  123.  
  124.                     return(NULL);
  125.                 }
  126.  
  127.                     /* Check if the class has been replaced, assuming that the
  128.                      * replacement will live in memory rather than in ROM space.
  129.                      */
  130.  
  131.                 if(TypeOfMem(OCLASS(MoreInfo->FrameImage)->cl_Dispatcher.h_Entry))
  132.                     MoreInfo->UseFrame = TRUE;
  133.             }
  134.  
  135.             return((ULONG)NewImage);
  136.         }
  137.     }
  138.  
  139.     return(NULL);
  140. }
  141.  
  142.  
  143. /*****************************************************************************/
  144.  
  145.  
  146. STATIC VOID
  147. ImageClassDispose(struct IClass *class,Object *object,Msg msg)
  148. {
  149.     struct ImageInfo *MoreInfo = INST_DATA(class,object);
  150.  
  151.     if(MoreInfo->Font)
  152.         CloseFont(MoreInfo->Font);
  153.  
  154.     if(MoreInfo->FrameImage)
  155.         DisposeObject(MoreInfo->FrameImage);
  156. }
  157.  
  158.  
  159. /*****************************************************************************/
  160.  
  161.  
  162. ULONG SAVE_DS ASM
  163. LTP_ImageDispatch(REG(a0) struct IClass *class,REG(a2) Object *object,REG(a1) Msg msg)
  164. {
  165.     switch(msg->MethodID)
  166.     {
  167.         case IM_ERASE:
  168.             return(ImageClassErase((struct Image *)object,(struct impErase *)msg));
  169.  
  170.         case IM_DRAW:
  171.             return(ImageClassDraw((struct Image *)object,(struct impDraw *)msg,(ImageInfo *)INST_DATA(class,object)));
  172.  
  173.         case OM_NEW:
  174.             return(ImageClassNew(class,object,(struct opSet *)msg));
  175.  
  176.         case OM_DISPOSE:
  177.             ImageClassDispose(class,object,msg);
  178.  
  179.             // Falls down to the default case...
  180.     }
  181.  
  182.     return(DoSuperMethodA(class,object,msg));
  183. }
  184.